﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using StockStar.GatherData;
using System.Data;
using System.Data.SqlClient;

namespace Stockstar.Stock.Gather
{
    public class GatherData
    {
        public bool DoWork()
        {
            LogFile.WriteLog("开始");
            IrtXgListUrl(1);
            UpXgListByUrl();

            IrtZfListUrl(1);
            UpZfListByUrl();

            IrtKzzListUrl(1);
            UpKzzListByUrl();

            IrtShListUrl(1);
            UpShListByUrl();

            LogFile.WriteLog("结束");
            return true;
            //Console.Read();
        }

        /// <summary>
        /// 根据url采集对应信息
        /// </summary>
        /// <param name="_url"></param>
        /// <returns>返回采集结果信息</returns>
        public string DoUpdate(string _url)
        {
            string relStr = "";
            if (string.IsNullOrEmpty(_url))
            {
                relStr = "请输入正确的链接地址!";
            }
            else
            {
                if (_url.Contains("http://data.eastmoney.com/xg/xg/"))
                {
                    List<XgDetailEntity> MidList = (List<XgDetailEntity>)NewsList.XgListAll("and url='" + _url + "' ");
                    if (MidList.Count > 0)
                    {
                        relStr = UpXgListByUrl(_url, MidList[0].ID);
                    }
                    else
                    {
                        StringBuilder sql = new StringBuilder();
                        sql.Append("insert XG_Detail (url,flag,createtime) values ('" + _url + "',-1,'" + DateTime.Now + "')      ;\n");
                        SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        int _ID = (int)SQLHelper.ExecuteScalar(SQLHelper.StrConn, CommandType.Text, "select top 1 id from XG_Detail order by id desc", null);
                        relStr = UpXgListByUrl(_url, _ID);
                    }
                }
                else if (_url.Contains("http://data.eastmoney.com/xg/zf/"))
                {
                    List<ZfDetailEntity> MidList = (List<ZfDetailEntity>)NewsList.ZfListAll("and url='" + _url + "' ");
                    if (MidList.Count > 0)
                    {
                        relStr = UpZfListByUrl(_url, MidList[0].ID);
                    }
                    else
                    {
                        StringBuilder sql = new StringBuilder();
                        sql.Append("insert ZF_Detail (url,flag,createtime) values ('" + _url + "',-1,'" + DateTime.Now + "')      ;\n");
                        SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        int _ID = (int)SQLHelper.ExecuteScalar(SQLHelper.StrConn, CommandType.Text, "select top 1 id from ZF_Detail order by id desc", null);
                        relStr = UpZfListByUrl(_url, _ID);
                    }
                }
                else if (_url.Contains("http://data.eastmoney.com/xg/kzz/"))
                {
                    List<KzzDetailEntity> MidList = (List<KzzDetailEntity>)NewsList.KzzListAll("and url='" + _url + "' ");
                    if (MidList.Count > 0)
                    {
                        relStr = UpKzzListByUrl(_url, MidList[0].ID);
                    }
                    else
                    {
                        StringBuilder sql = new StringBuilder();
                        sql.Append("insert KZZ_Detail (url,flag,createtime) values ('" + _url + "',-1,'" + DateTime.Now + "')      ;\n");
                        SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        int _ID = (int)SQLHelper.ExecuteScalar(SQLHelper.StrConn, CommandType.Text, "select top 1 id from KZZ_Detail order by id desc", null);
                        relStr = UpKzzListByUrl(_url, _ID);
                    }
                }
                else if (_url.Contains("http://data.eastmoney.com/xg/gh/"))
                {
                    List<ShDetailEntity> MidList = (List<ShDetailEntity>)NewsList.ShListAll("and url='" + _url + "' ");
                    if (MidList.Count > 0)
                    {
                        relStr = UpShListByUrl(_url, MidList[0].ID);
                    }
                    else
                    {
                        StringBuilder sql = new StringBuilder();
                        sql.Append("insert SH_Detail (url,flag,createtime) values ('" + _url + "',-1,'" + DateTime.Now + "')      ;\n");
                        SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        int _ID = (int)SQLHelper.ExecuteScalar(SQLHelper.StrConn, CommandType.Text, "select top 1 id from SH_Detail order by id desc", null);
                        relStr = UpShListByUrl(_url, _ID);
                    }
                }
                else
                {
                    relStr = "请输入正确的网址!";
                }

            }
            return relStr;
        }

        /// <summary>
        /// 采集最新列表信息
        /// </summary>
        /// <returns></returns>
        public bool DoList()
        {
            LogFile.WriteLog("开始");

            IrtXgListUrl(1);

            IrtZfListUrl(1);

            IrtKzzListUrl(1);

            IrtShListUrl(1);

            LogFile.WriteLog("结束");

            return true;
        }

        /// <summary>
        /// 采集新投http://data.eastmoney.com/xg/xg/default.html UrlList
        /// </summary>
        /// <param name="page">传入采集第几页,page=0采集所有页</param>
        private static void IrtXgListUrl(int page)
        {
            StringBuilder sql = new StringBuilder();
            List<XgDetailEntity> ListAll = (List<XgDetailEntity>)NewsList.XgListAll("");

            string _url = "", _Content = "";
            int _page = 1;
            if (page == 0)
            {
                _url = "http://data.eastmoney.com/xg/xg/default.html";
                _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                Match mc = Regex.Match(_Content, "(?<=<tr class=\"list_pager\">)[\\s\\S]*?(?=</tr>)");
                if (mc.Length > 0)
                {
                    Match mc2 = Regex.Match(mc.Value, "(?<=共)[\\s\\S]*?(?=页)", RegexOptions.IgnoreCase);
                    if (mc2.Length > 0)
                        _page = OperMethod.ToInt(OperMethod.StrReplaceHtml(mc2.Value));
                }
            }

            for (int i = 1; i <= _page; i++)
            {
                try
                {
                    _url = "http://data.eastmoney.com/xg/xg/sgrq/" + i.ToString() + ".html";
                    _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    MatchCollection mc = Regex.Matches(_Content, "(?<=title=\"按股票代码排序\")[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                    if (mc.Count > 0)
                    {
                        #region
                        MatchCollection mc2 = Regex.Matches(mc[0].Value, "<a[^>]+>[\\S\\s]*?</a>", RegexOptions.IgnoreCase);
                        if (mc2.Count > 0)
                        {
                            for (int j = 0; j < mc2.Count; j++)
                            {
                                try
                                {
                                    if (mc2[j].Value.Contains("详细"))
                                    {
                                        Match mc3 = Regex.Match(mc2[j].Value, "(?<=<a href=\")[\\s\\S]*?(?=\")");
                                        if (mc3.Length > 0)
                                        {
                                            XgDetailEntity et = new XgDetailEntity();
                                            et.Url = "http://data.eastmoney.com" + OperMethod.StrReplaceHtml(mc3.Value);
                                            string _gpdm = "";
                                            Match mcdm = Regex.Match(mc3.Value, "\\d{6}", RegexOptions.IgnoreCase);
                                            if (mcdm.Length > 0)
                                            {
                                                _gpdm = mcdm.Value;
                                            }

                                            List<XgDetailEntity> MidList = (List<XgDetailEntity>)ListAll.Where(o => o.Url.Equals(et.Url) || o.Gpdm.Equals(_gpdm)).ToList();
                                            if (MidList == null || MidList.Count < 1)
                                            {
                                                sql.Append("insert XG_Detail (url,flag,createtime) values ('" + et.Url + "',-1,'" + DateTime.Now + "')      ;\n");
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("取列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                                    //LogFile.WriteLog("取列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                                }
                            }
                        }
                        #endregion
                    }

                    if (!string.IsNullOrEmpty(sql.ToString()))
                    {
                        SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        sql = new StringBuilder();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("取新股第" + i + "页信息时出错");
                    //LogFile.WriteLog("取新股第" + i + "页信息时出错");
                }
            }
        }

        /// <summary>
        /// 更新新股UrlList信息
        /// </summary>
        private static void UpXgListByUrl()
        {
            StringBuilder sql = new StringBuilder();
            List<XgDetailEntity> MidList = (List<XgDetailEntity>)NewsList.XgListAll("and flag=-1");
            for (int i = 0; i < MidList.Count; i++)
            {
                try
                {
                    Console.WriteLine("采集第i=" + i.ToString() + "条信息");
                    string _url = MidList[i].Url;
                    int _ID = MidList[i].ID;
                    UpXgListByUrl(_url, _ID);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集第i=" + i.ToString() + "条信息异常" + ex.Message);
                    //LogFile.WriteLog("采集第i=" + i.ToString() + "条信息异常" + ex.Message);
                }
            }
            Console.WriteLine("新股信息更新成功");
        }

        private static string UpXgListByUrl(string _url, int _ID)
        {
            Regex regex = new Regex("<td[^>][\\S\\s]*?>|</td>|<div[^>][\\S\\s]*?>|</div>");
            //_url = "http://data.eastmoney.com/xg/xg/detail/300054.html";
            string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
            Match mcSubCon = Regex.Match(_Content, "(?<=id=\"content\" class=\"mainbox\">)[\\s\\S]*?(?=id=\"footer\">)", RegexOptions.IgnoreCase);
            if (!string.IsNullOrEmpty(mcSubCon.Value))
            {
                //XG_Detail新股详细资料
                #region
                StringBuilder sbDetail = new StringBuilder();
                Match mcDetail = Regex.Match(mcSubCon.Value, "(?<=class=\"detail\">)[\\s\\S]*?(?=<div class=\"s8\"></div>)", RegexOptions.IgnoreCase);
                if (string.IsNullOrEmpty(mcDetail.Value))
                    mcDetail = Regex.Match(mcSubCon.Value, "(?<=class=\"detail\">)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);

                if (!string.IsNullOrEmpty(mcDetail.Value))
                {
                    XgDetailEntity et = new XgDetailEntity();
                    MatchCollection mcTd = Regex.Matches(mcDetail.Value, "<td[\\S\\s]*?>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                    DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
                    for (int j = 0; j < mcTd.Count; j++)
                    {
                        #region
                        try
                        {
                            if (mcTd[j].Value.Contains("股票代码"))
                            {
                                j++;
                                et.Gpdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("股票简称"))
                            {
                                j++;
                                et.Gpjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("申购代码"))
                            {
                                j++;
                                et.Sgdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("上市地点"))
                            {
                                j++;
                                et.Ssdd = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("发行价格"))
                            {
                                j++;
                                et.Fxjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("发行市盈率"))
                            {
                                j++;
                                et.Fxsyl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("发行面值"))
                            {
                                j++;
                                et.Fxmz = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("实际募集资金总额"))
                            {
                                j++;
                                et.Mjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("网上发行日期"))
                            {
                                j++;
                                et.Fxrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("网上发行股数"))
                            {
                                j++;
                                et.Fxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("网下配售日期"))
                            {
                                j++;
                                et.Psrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("网下配售股数"))
                            {
                                j++;
                                et.Psgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("申购数量上限"))
                            {
                                j++;
                                et.Sgsl = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("总发行股数"))
                            {
                                j++;
                                et.Zfxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("中签号公告日"))
                            {
                                j++;
                                et.Zqhggr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("上市日期"))
                            {
                                j++;
                                et.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("网下配售比例"))
                            {
                                j++;
                                et.Psbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("网下配售冻结资金"))
                            {
                                j++;
                                et.Psdjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("网上发行中签率"))
                            {
                                j++;
                                et.Fxzql = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("网上申购冻结资金"))
                            {
                                j++;
                                et.Sgdjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("网上发行每中一签约"))
                            {
                                j++;
                                et.Fxqy = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("冻结资金总计"))
                            {
                                j++;
                                et.Djzjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("中签号"))
                            {
                                j++;
                                et.Zqh = OperMethod.FormatHtml(mcTd[j].Value);
                                et.Zqh = regex.Replace(et.Zqh, "");
                                continue;
                            }
                            if (mcTd[j].Value.Contains("公司简介"))
                            {
                                j++;
                                et.Gsjj = OperMethod.FormatHtml(mcTd[j].Value);
                                et.Gsjj = regex.Replace(et.Gsjj, "");
                                continue;
                            }
                            if (mcTd[j].Value.Contains("主营业务"))
                            {
                                j++;
                                et.Zyyw = OperMethod.FormatHtml(mcTd[j].Value);
                                et.Zyyw = regex.Replace(et.Zyyw, "");
                                continue;
                            }
                            if (mcTd[j].Value.Contains("发行前每股净资产"))
                            {
                                j++;
                                et.Fxq = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("发行后每股净资产"))
                            {
                                j++;
                                et.Fxh = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("上市推荐人"))
                            {
                                j++;
                                et.Tjr = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("承销方式"))
                            {
                                j++;
                                et.Cxfs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("副主承销商"))
                            {
                                j++;
                                et.Fzcxs = OperMethod.FormatHtml(mcTd[j].Value);
                                et.Fzcxs = regex.Replace(et.Fzcxs, "");
                                continue;
                            }
                            if (mcTd[j].Value.Contains("主承销商"))
                            {
                                j++;
                                et.Zcxs = OperMethod.FormatHtml(mcTd[j].Value);
                                et.Zcxs = regex.Replace(et.Zcxs, "");
                                continue;
                            }
                            if (mcTd[j].Value.Contains("股利分配政策"))
                            {
                                j++;
                                et.Glfpzc = OperMethod.FormatHtml(mcTd[j].Value);
                                et.Glfpzc = regex.Replace(et.Glfpzc, "");
                                continue;
                            }
                            if (mcTd[j].Value.Contains("首日开盘价"))
                            {
                                j++;
                                et.Kpj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("首日收盘价"))
                            {
                                j++;
                                et.Spj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("首日涨幅"))
                            {
                                j++;
                                et.Zf = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("首日换手率"))
                            {
                                j++;
                                et.Hsl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Detail取字段" + mcTd[j].Value + "附近异常:" + ex.Message);
                            //LogFile.WriteLog("Detail取字段" + mcTd[j].Value + "附近异常:" + ex.Message);
                        }
                        #endregion
                    }

                    //拼sbDetail Sql
                    #region
                    sbDetail.Append("UPDATE [XG_Detail]");
                    sbDetail.Append(" SET [flag] = 0");
                    sbDetail.Append(" ,[gpdm] = '" + et.Gpdm + "'");
                    sbDetail.Append(" ,[gpjc] = '" + et.Gpjc + "'");
                    sbDetail.Append(" ,[sgdm] = '" + et.Sgdm + "'");
                    sbDetail.Append(" ,[ssdd] = '" + et.Ssdd + "'");
                    sbDetail.Append(" ,[fxjg] = " + et.Fxjg + "");
                    sbDetail.Append(" ,[fxsyl] = " + et.Fxsyl + "");
                    sbDetail.Append(" ,[fxmz] = " + et.Fxmz + "");
                    sbDetail.Append(" ,[mjzj] = " + et.Mjzj + "");
                    sbDetail.Append(" ,[fxrq] = '" + et.Fxrq + "'");
                    sbDetail.Append(" ,[fxgs] = " + et.Fxgs + "");
                    sbDetail.Append(" ,[psrq] = '" + et.Psrq + "'");
                    sbDetail.Append(" ,[psgs] = " + et.Psgs + "");
                    sbDetail.Append(" ,[sgsl] = " + et.Sgsl + "");
                    sbDetail.Append(" ,[zfxgs] = " + et.Zfxgs + "");
                    sbDetail.Append(" ,[zqhggr] = '" + et.Zqhggr + "'");
                    sbDetail.Append(" ,[ssrq] = '" + et.Ssrq + "'");
                    sbDetail.Append(" ,[psbl] = " + et.Psbl + "");
                    sbDetail.Append(" ,[psdjzj] = " + et.Psdjzj + "");
                    sbDetail.Append(" ,[fxzql] = " + et.Fxzql + "");
                    sbDetail.Append(" ,[sgdjzj] = " + et.Sgdjzj + "");
                    sbDetail.Append(" ,[fxqy] = " + et.Fxqy + "");
                    sbDetail.Append(" ,[Djzjzj] = " + et.Djzjzj + "");
                    sbDetail.Append(" ,[zqh] = '" + et.Zqh + "'");
                    sbDetail.Append(" ,[gsjj] = '" + et.Gsjj + "'");
                    sbDetail.Append(" ,[zyyw] = '" + et.Zyyw + "'");
                    sbDetail.Append(" ,[fxq] = " + et.Fxq + "");
                    sbDetail.Append(" ,[fxh] = " + et.Fxh + "");
                    sbDetail.Append(" ,[tjr] = '" + et.Tjr + "'");
                    sbDetail.Append(" ,[cxfs] = '" + et.Cxfs + "'");
                    sbDetail.Append(" ,[zcxs] = '" + et.Zcxs + "'");
                    sbDetail.Append(" ,[fzcxs] = '" + et.Fzcxs + "'");
                    sbDetail.Append(" ,[glfpzc] = '" + et.Glfpzc + "'");
                    sbDetail.Append(" ,[kpj] = " + et.Kpj + "");
                    sbDetail.Append(" ,[spj] = " + et.Spj + "");
                    sbDetail.Append(" ,[zf] = " + et.Zf + "");
                    sbDetail.Append(" ,[hsl] = " + et.Hsl + "");
                    sbDetail.Append(" ,[createtime] = '" + DateTime.Now + "'");
                    sbDetail.Append(" WHERE ID=" + _ID);
                    Console.WriteLine("Detail拼Sql完成");
                    #endregion
                }
                #endregion

                //XG_Invset投资项目
                #region
                StringBuilder sbInvset = new StringBuilder();
                Match mcInvset = Regex.Match(mcSubCon.Value, "(?<=募集资金用途将用于的项目</div>)[\\s\\S]*?(?=<div class=\"s8\"></div>)", RegexOptions.IgnoreCase);
                if (!string.IsNullOrEmpty(mcInvset.Value))
                {
                    MatchCollection mcTr = Regex.Matches(mcInvset.Value, "(?<=class=\"list_eve\">)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                    for (int k = 0; k < mcTr.Count; k++)
                    {
                        try
                        {
                            MatchCollection mcTd = Regex.Matches(mcTr[k].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                            if (mcTd.Count == 3)
                            {
                                XgInvsetEntity et = new XgInvsetEntity();
                                et.Xmmc = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                et.Tzje = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[2].Value));
                                sbInvset.Append("Insert into XG_Invset (id,xmmc,tzje) values (" + _ID + ",'" + et.Xmmc + "'," + et.Tzje + ")    ;\n");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("募集资金用途将用于的项目异常:" + ex.Message);
                            //LogFile.WriteLog("募集资金用途将用于的项目异常:" + ex.Message);
                        }
                    }
                }
                Console.WriteLine("取XG_Invset投资项目信息完成");
                #endregion

                //XG_Indicators财务指标
                #region
                StringBuilder sbIndicator = new StringBuilder();
                Match mcIndicator = Regex.Match(mcSubCon.Value, "(?<=最近三年财务指标</div>)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                if (!string.IsNullOrEmpty(mcIndicator.Value))
                {
                    List<EntityIndicatorCol> CList = new List<EntityIndicatorCol>();
                    MatchCollection mcTr = Regex.Matches(mcIndicator.Value, "(?<=<tr)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                    for (int m = 0; m < mcTr.Count; m++)
                    {
                        try
                        {
                            EntityIndicatorCol cet = new EntityIndicatorCol();
                            if (mcTr[m].Value.Contains("class=\"subhead\">"))
                            {
                                MatchCollection mcTd = Regex.Matches(mcTr[m].Value, "<th[\\S\\s]*?>[\\S\\s]*?</th>", RegexOptions.IgnoreCase);
                                if (mcTd.Count > 0)
                                {
                                    cet.zd = OperMethod.StrReplaceHtml(mcTd[0].Value);
                                    cet.c1 = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                    cet.c2 = OperMethod.StrReplaceHtml(mcTd[2].Value);
                                    cet.c3 = OperMethod.StrReplaceHtml(mcTd[3].Value);
                                    CList.Add(cet);
                                }
                                continue;
                            }
                            if (mcTr[m].Value.Contains("class=\"list_eve\">"))
                            {
                                MatchCollection mcTd = Regex.Matches(mcTr[m].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                                if (mcTd.Count > 0)
                                {
                                    cet.zd = OperMethod.StrReplaceHtml(mcTd[0].Value);
                                    cet.c1 = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                    cet.c2 = OperMethod.StrReplaceHtml(mcTd[2].Value);
                                    cet.c3 = OperMethod.StrReplaceHtml(mcTd[3].Value);
                                    CList.Add(cet);
                                }
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("解析装载到List出错:" + ex.Message);
                            //LogFile.WriteLog("解析装载到List出错:" + ex.Message);
                        }
                    }

                    if (CList.Count == 11)
                    {
                        sbIndicator.Append(" INSERT INTO [XG_Indicators] ");
                        sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                        sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c1 + "'," + OperMethod.ToDeceimal(CList[1].c1) + "," + OperMethod.ToDeceimal(CList[2].c1) + "," + OperMethod.ToDeceimal(CList[3].c1) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c1) + "," + OperMethod.ToDeceimal(CList[5].c1) + "," + OperMethod.ToDeceimal(CList[6].c1) + "," + OperMethod.ToDeceimal(CList[7].c1) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c1) + "," + OperMethod.ToDeceimal(CList[9].c1) + "," + OperMethod.ToDeceimal(CList[10].c1) + ")    ;\n");

                        sbIndicator.Append(" INSERT INTO [XG_Indicators] ");
                        sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                        sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c2 + "'," + OperMethod.ToDeceimal(CList[1].c2) + "," + OperMethod.ToDeceimal(CList[2].c2) + "," + OperMethod.ToDeceimal(CList[3].c2) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c2) + "," + OperMethod.ToDeceimal(CList[5].c2) + "," + OperMethod.ToDeceimal(CList[6].c2) + "," + OperMethod.ToDeceimal(CList[7].c2) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c2) + "," + OperMethod.ToDeceimal(CList[9].c2) + "," + OperMethod.ToDeceimal(CList[10].c2) + ")    ;\n");

                        sbIndicator.Append(" INSERT INTO [XG_Indicators] ");
                        sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                        sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c3 + "'," + OperMethod.ToDeceimal(CList[1].c3) + "," + OperMethod.ToDeceimal(CList[2].c3) + "," + OperMethod.ToDeceimal(CList[3].c3) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c3) + "," + OperMethod.ToDeceimal(CList[5].c3) + "," + OperMethod.ToDeceimal(CList[6].c3) + "," + OperMethod.ToDeceimal(CList[7].c3) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c3) + "," + OperMethod.ToDeceimal(CList[9].c3) + "," + OperMethod.ToDeceimal(CList[10].c3) + ")    ;\n");
                    }
                }
                Console.WriteLine("取XG_Indicators最近三年财务指标完成");
                #endregion

                //XG_Partner主要股东
                #region
                StringBuilder sbPartner = new StringBuilder();
                Match mcPartner = Regex.Match(mcSubCon.Value, "(?<=主要股东</div>)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                if (!string.IsNullOrEmpty(mcPartner.Value))
                {
                    MatchCollection mcTr = Regex.Matches(mcPartner.Value, "(?<=class=\"list_eve\">)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                    for (int x = 0; x < mcTr.Count; x++)
                    {
                        try
                        {
                            MatchCollection mcTd = Regex.Matches(mcTr[x].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                            if (mcTd.Count == 4)
                            {
                                XgPaterEntity et = new XgPaterEntity();
                                et.Gdmc = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                et.Cgsl = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[2].Value));
                                et.Gbbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[3].Value));
                                sbPartner.Append("INSERT INTO [XG_Partner] ([id],[gdmc],[cgsl],[gbbl]) VALUES (" + _ID + ",'" + et.Gdmc + "'," + et.Cgsl + "," + et.Gbbl + ")    ;\n");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("主要股东异常:" + ex.Message);
                            //LogFile.WriteLog("主要股东异常:" + ex.Message);
                        }
                    }
                }
                Console.WriteLine("取XG_Partner主要股东完成");
                #endregion

                //执行Sql
                #region
                using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(sbDetail.ToString()))
                            {
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbDetail.ToString(), null);
                            }
                            if (!string.IsNullOrEmpty(sbInvset.ToString()))
                            {
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, "DELETE FROM XG_Invset WHERE id=" + _ID, null);
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbInvset.ToString(), null);
                            }
                            if (!string.IsNullOrEmpty(sbIndicator.ToString()))
                            {
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, "DELETE FROM XG_Indicators WHERE id=" + _ID, null);
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbIndicator.ToString(), null);
                            }
                            if (!string.IsNullOrEmpty(sbPartner.ToString()))
                            {
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, "DELETE FROM XG_Partner WHERE id=" + _ID, null);
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbPartner.ToString(), null);
                            }
                            trans.Commit();
                            Console.WriteLine("ID=" + _ID + ",Url=" + _url + "信息更新成功!");
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            Console.WriteLine("执行Sql异常,ID:" + _ID + ":" + ex.Message);
                            //LogFile.WriteLog("执行Sql异常,ID:" + _ID + ":" + ex.Message);
                        }
                        finally
                        {
                            sbDetail = new StringBuilder();
                            sbInvset = new StringBuilder();
                            sbIndicator = new StringBuilder();
                            sbPartner = new StringBuilder();
                        }
                    }
                }
                #endregion

                return "信息更新成功!";
            }
            else
            {
                return "链接不正确或不可访问!";
            }
        }



        /// <summary>
        /// 采集 东财增发申购数据 http://data.eastmoney.com/xg/zf/default.html UrlList
        /// </summary>
        /// <param name="page">传入采集第几页,page=0采集所有页</param>
        private static void IrtZfListUrl(int page)
        {
            StringBuilder sql = new StringBuilder();
            List<ZfDetailEntity> ListAll = new List<ZfDetailEntity>();
            ListAll = (List<ZfDetailEntity>)NewsList.ZfListAll("");

            string _url = "", _Content = "";
            int _page = 1;

            for (int i = 1; i <= _page; i++)
            {
                try
                {
                    _url = "http://data.eastmoney.com/xg/zf/default.html";
                    _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mc = Regex.Match(_Content, "(?<=class=\"rpager\">当前第)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mc.Value))
                    {
                        #region
                        MatchCollection mc2 = Regex.Matches(mc.Value, "href=\"/xg/zf/detail/\\d{6}.html\" class=\"red\">详细</a", RegexOptions.IgnoreCase);
                        for (int j = 0; j < mc2.Count; j++)
                        {
                            try
                            {
                                Match mc3 = Regex.Match(mc2[j].Value, "(?<=href=\")[\\s\\S]*?(?=\")", RegexOptions.IgnoreCase);
                                if (mc3.Length > 0)
                                {
                                    ZfDetailEntity et = new ZfDetailEntity();
                                    et.Url = "http://data.eastmoney.com" + OperMethod.StrReplaceHtml(mc3.Value);
                                    List<ZfDetailEntity> MidList = (List<ZfDetailEntity>)ListAll.Where(o => o.Url.Equals(et.Url)).ToList();
                                    if (MidList == null || MidList.Count < 1)
                                    {
                                        sql.Append("insert ZF_Detail (url,flag,createtime) values ('" + et.Url + "',-1,'" + DateTime.Now + "')      ;\n");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("取列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                                //LogFile.WriteLog("取列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                            }
                        }
                        #endregion
                    }

                    if (!string.IsNullOrEmpty(sql.ToString()))
                    {
                        SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        sql = new StringBuilder();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集东财增发申购数据第" + i + "页信息时出错");
                    //LogFile.WriteLog("采集东财增发申购数据第" + i + "页信息时出错");
                }
            }
            Console.WriteLine("采集东财增发申购数据列表完成");
        }

        /// <summary>
        /// 更新东财增发申购数据UrlList信息
        /// </summary>
        private static void UpZfListByUrl()
        {
            List<ZfDetailEntity> MidList = (List<ZfDetailEntity>)NewsList.ZfListAll(" and flag=-1");
            for (int i = 0; i < MidList.Count; i++)
            {
                try
                {
                    Console.WriteLine("采集东财增发申购数据第i=" + i.ToString() + "条信息");
                    string _url = MidList[i].Url;
                    int _ID = MidList[i].ID;
                    UpZfListByUrl(_url, _ID);
                }
                catch (Exception ex)
                { }
            }
        }

        private static string UpZfListByUrl(string _url, int _ID)
        {
            StringBuilder sbZfDetail = new StringBuilder();
            //_url = "http://data.eastmoney.com/xg/zf/detail/600481.html";
            string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
            Match mcSubCon = Regex.Match(_Content, "(?<=id=\"content\">)[\\s\\S]*?(?=id=\"footer\">)", RegexOptions.IgnoreCase);
            if (!string.IsNullOrEmpty(mcSubCon.Value))
            {
                //Zf_Detail东财增发详细资料
                #region
                ZfDetailEntity et = new ZfDetailEntity();
                MatchCollection mcTd = Regex.Matches(mcSubCon.Value, "<td[\\S\\s]*?>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
                for (int j = 0; j < mcTd.Count; j++)
                {
                    #region
                    try
                    {
                        Regex regex = new Regex("<td[^>][\\S\\s]*?>|</td>|<div[^>][\\S\\s]*?>|</div>");
                        if (mcTd[j].Value.Contains("增发代码"))
                        {
                            j++;
                            et.Zfdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("增发简称"))
                        {
                            j++;
                            et.Zfjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("股票代码"))
                        {
                            j++;
                            et.Gpdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("股票简称"))
                        {
                            j++;
                            et.Gpjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("发行方式"))
                        {
                            j++;
                            et.Fxfs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("发行价格"))
                        {
                            j++;
                            et.Fxjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("网上发行日期"))
                        {
                            j++;
                            et.Fxrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("网上发行股数"))
                        {

                            if (mcTd[j].Value.Contains("万股"))
                            {
                                j++;
                                et.Fxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                et.Fxgs = et.Fxgs * 10000;
                            }
                            else
                            {
                                j++;
                                et.Fxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));

                            }
                            continue;
                        }
                        if (mcTd[j].Value.Contains("网下发行日期"))
                        {
                            j++;
                            et.Psrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("网下配售股数"))
                        {
                            if (mcTd[j].Value.Contains("万股"))
                            {
                                j++;
                                et.Psgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                et.Psgs = et.Fxgs * 10000;
                            }
                            else
                            {
                                j++;
                                et.Psgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            }
                            continue;
                        }
                        if (mcTd[j].Value.Contains("增发上市日期"))
                        {
                            j++;
                            et.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("总发行股数"))
                        {
                            if (mcTd[j].Value.Contains("万股"))
                            {
                                j++;
                                et.Zfxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                et.Zfxgs = et.Fxgs * 10000;
                            }
                            else
                            {
                                j++;
                                et.Zfxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            }
                            continue;
                        }
                        if (mcTd[j].Value.Contains("发行结果公布日") || mcTd[j].Value.Contains("中签号公布日"))
                        {
                            j++;
                            et.Zqr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("网上发行配售率") || mcTd[j].Value.Contains("网上发行中签率"))
                        {
                            j++;
                            et.Zql = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("冻结资金"))
                        {
                            j++;
                            et.Djzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("每中一股资金"))
                        {
                            j++;
                            et.Ygzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("中签号"))
                        {
                            j++;
                            et.Zqh = OperMethod.FormatHtml(mcTd[j].Value);
                            et.Zqh = regex.Replace(et.Zqh, "");
                            continue;
                        }
                        if (mcTd[j].Value.Contains("募集资金用途"))
                        {
                            j++;
                            et.Zjyt = OperMethod.FormatHtml(mcTd[j].Value);
                            et.Zjyt = regex.Replace(et.Zjyt, "");
                            continue;
                        }
                        if (mcTd[j].Value.Contains("主营业务"))
                        {
                            j++;
                            et.Zyyw = OperMethod.FormatHtml(mcTd[j].Value);
                            et.Zyyw = regex.Replace(et.Zyyw, "");
                            continue;
                        }
                        if (mcTd[j].Value.Contains("发行前总股本"))
                        {
                            j++;
                            et.Fxqzgb = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("发行后总股本"))
                        {
                            j++;
                            et.FxhZgb = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("承销方式"))
                        {
                            j++;
                            et.Cxfs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("承销期起止时间"))
                        {
                            j++;
                            et.Cxqzsj = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("副主承销商"))
                        {
                            j++;
                            et.Fzcxs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("主承销商"))
                        {
                            j++;
                            et.Zcxs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("首日开盘价"))
                        {
                            j++;
                            et.Kpj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("首日收盘价"))
                        {
                            j++;
                            et.Spj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("首日涨幅"))
                        {
                            j++;
                            et.Zf = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }

                    }
                    catch (Exception ex)
                    { }
                    #endregion
                }
                #endregion

                //拼Sql
                #region
                sbZfDetail.Append(" UPDATE [ZF_Detail]");
                sbZfDetail.Append(" SET [flag] = 0");
                sbZfDetail.Append(" ,[zfdm] = '" + et.Zfdm + "'");
                sbZfDetail.Append(" ,[zfjc] = '" + et.Zfjc + "'");
                sbZfDetail.Append(" ,[gpdm] = '" + et.Gpdm + "'");
                sbZfDetail.Append(" ,[gpjc] = '" + et.Gpjc + "'");
                sbZfDetail.Append(" ,[fxfs] = '" + et.Fxfs + "'");
                sbZfDetail.Append(" ,[fxjg] = " + et.Fxjg + "");
                sbZfDetail.Append(" ,[fxrq] = '" + et.Fxrq + "'");
                sbZfDetail.Append(" ,[fxgs] = " + et.Fxgs + "");
                sbZfDetail.Append(" ,[psrq] = '" + et.Psrq + "'");
                sbZfDetail.Append(" ,[psgs] = " + et.Psgs + "");
                sbZfDetail.Append(" ,[ssrq] = '" + et.Ssrq + "'");
                sbZfDetail.Append(" ,[zfxgs] = " + et.Zfxgs + "");
                sbZfDetail.Append(" ,[zqr] = '" + et.Zqr + "'");
                sbZfDetail.Append(" ,[zql] = " + et.Zql + "");
                sbZfDetail.Append(" ,[djzj] = " + et.Djzj + "");
                sbZfDetail.Append(" ,[ygzj] = " + et.Ygzj + "");
                sbZfDetail.Append(" ,[zqh] = '" + et.Zqh + "'");
                sbZfDetail.Append(" ,[zjyt] = '" + et.Zjyt + "'");
                sbZfDetail.Append(" ,[zyyw] = '" + et.Zyyw + "'");
                sbZfDetail.Append(" ,[fxqzgb] = " + et.Fxqzgb + "");
                sbZfDetail.Append(" ,[fxhzgb] = " + et.FxhZgb + "");
                sbZfDetail.Append(" ,[cxfs] = '" + et.Cxfs + "'");
                sbZfDetail.Append(" ,[cxqzsj] = '" + et.Cxqzsj + "'");
                sbZfDetail.Append(" ,[zcxs] = '" + et.Zcxs + "'");
                sbZfDetail.Append(" ,[fzcxs] = '" + et.Fzcxs + "'");
                sbZfDetail.Append(" ,[kpj] = " + et.Kpj + "");
                sbZfDetail.Append(" ,[spj] = " + et.Spj + "");
                sbZfDetail.Append(" ,[zf] = " + et.Zf + "");
                sbZfDetail.Append(" ,[stype] = '" + et.Stype + "'");
                sbZfDetail.Append(" ,[createtime] = '" + DateTime.Now + "'");
                sbZfDetail.Append(" WHERE id=" + _ID);
                #endregion

                if (!string.IsNullOrEmpty(sbZfDetail.ToString()))
                {
                    int n = 0;
                    try
                    {
                        n = SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sbZfDetail.ToString(), null);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    sbZfDetail = new StringBuilder();
                    Console.WriteLine("本次更新" + n.ToString() + "条东财增发申购数据信息。");
                }
                return "信息更新成功!";
            }
            else
            {
                return "链接地址错误或不可访问!";
            }
        }

        /// <summary>
        /// 采集 可转债股票数据 http://data.eastmoney.com/xg/kzz/default.html  UrlList
        /// </summary>
        /// <param name="page">传入采集第几页,page=0采集所有页</param>
        private static void IrtKzzListUrl(int page)
        {
            StringBuilder sql = new StringBuilder();
            List<KzzDetailEntity> ListAll = new List<KzzDetailEntity>();
            ListAll = (List<KzzDetailEntity>)NewsList.KzzListAll("");

            string _url = "", _Content = "";
            int _page = 1;

            for (int i = 1; i <= _page; i++)
            {
                try
                {
                    _url = "http://data.eastmoney.com/xg/kzz/default.html ";
                    _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mc = Regex.Match(_Content, "(?<=class=\"rpager\">当前第)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mc.Value))
                    {
                        #region
                        MatchCollection mc2 = Regex.Matches(mc.Value, "href=\"/xg/kzz/detail/\\d{6}.html\" class=\"red\">详细</a", RegexOptions.IgnoreCase);
                        for (int j = 0; j < mc2.Count; j++)
                        {
                            try
                            {
                                Match mc3 = Regex.Match(mc2[j].Value, "(?<=href=\")[\\s\\S]*?(?=\")", RegexOptions.IgnoreCase);
                                if (mc3.Length > 0)
                                {
                                    KzzDetailEntity et = new KzzDetailEntity();
                                    et.Url = "http://data.eastmoney.com" + OperMethod.StrReplaceHtml(mc3.Value);
                                    List<KzzDetailEntity> MidList = (List<KzzDetailEntity>)ListAll.Where(o => o.Url.Equals(et.Url)).ToList();
                                    if (MidList == null || MidList.Count < 1)
                                    {
                                        sql.Append("insert Kzz_Detail (url,flag,createtime) values ('" + et.Url + "',-1,'" + DateTime.Now + "')      ;\n");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("采集可转债股票数据列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                                //LogFile.WriteLog("采集可转债股票数据列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                            }
                        }
                        #endregion
                    }

                    if (!string.IsNullOrEmpty(sql.ToString()))
                    {
                        int n = SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        sql = new StringBuilder();
                        Console.WriteLine("采集到可转债股票数据" + n.ToString() + "条");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集可转债股票数据第" + i + "页信息时出错");
                    //LogFile.WriteLog("采集可转债股票数据第" + i + "页信息时出错");
                }
            }
            Console.WriteLine("采集可转债股票数据列表完成");
        }


        /// <summary>
        /// 更新 可转债股票数据 UrlList信息
        /// </summary>
        private static void UpKzzListByUrl()
        {
            List<KzzDetailEntity> MidList = (List<KzzDetailEntity>)NewsList.KzzListAll(" and flag=-1 ");
            for (int i = 0; i < MidList.Count; i++)
            {
                try
                {
                    Console.WriteLine("采集可转债股票数据第i=" + i.ToString() + "条信息");
                    string _url = MidList[i].Url;
                    int _ID = MidList[i].ID;
                    UpKzzListByUrl(_url, _ID);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集更新第" + i.ToString() + "条信息时出错：" + ex.Message);
                    //LogFile.WriteLog("采集更新第" + i.ToString() + "条信息时出错：" + ex.Message);
                }
            }
        }

        private static string UpKzzListByUrl(string _url, int _ID)
        {
            StringBuilder sbKzzDetail = new StringBuilder();
            StringBuilder sbWarrant = new StringBuilder();
            //_url = "http://data.eastmoney.com/xg/kzz/detail/126018.html";
            string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
            Match mcSubCon = Regex.Match(_Content, "(?<=id=\"content\">)[\\s\\S]*?(?=id=\"footer\">)", RegexOptions.IgnoreCase);
            if (!string.IsNullOrEmpty(mcSubCon.Value))
            {
                //Kzz_Detail东财增发详细资料
                #region
                KzzDetailEntity et = new KzzDetailEntity();
                KZZWarrantEntity etw = new KZZWarrantEntity();
                MatchCollection mcTd = Regex.Matches(mcSubCon.Value, "<td[\\S\\s]*?>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
                for (int j = 0; j < mcTd.Count; j++)
                {
                    #region
                    try
                    {
                        Regex regex = new Regex("<td[^>][\\S\\s]*?>|</td>|<div[^>][\\S\\s]*?>|</div>");
                        if (mcTd[j].Value.Contains("债券代码"))
                        {
                            j++;
                            et.Zqdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("债券简称"))
                        {
                            j++;
                            et.Zqjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("股票代码"))
                        {
                            j++;
                            et.Gpdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("股票简称"))
                        {
                            j++;
                            et.Gpjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("认购代码"))
                        {
                            j++;
                            et.Rgdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("认购简称"))
                        {
                            j++;
                            et.Rgjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("申购代码"))
                        {
                            j++;
                            et.Sgdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("申购简称"))
                        {
                            j++;
                            et.Sgjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("信用级别"))
                        {
                            j++;
                            et.Xyjb = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("评级机构"))
                        {
                            j++;
                            et.Pjjg = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("转股期") || mcTd[j].Value.Contains("预设利率区间"))
                        {
                            j++;
                            et.Ztq = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("初始转股价格") || mcTd[j].Value.Contains("最终发行利率"))
                        {
                            j++;
                            et.Ztjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("发行份额"))
                        {
                            j++;
                            et.Fxfe = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("发行价格"))
                        {
                            j++;
                            et.Fxjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("债券期限"))
                        {
                            j++;
                            et.Zqqx = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("网上网下发行比例"))
                        {
                            j++;
                            et.Fxbl = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("申购日期"))
                        {
                            j++;
                            et.Sgrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("配售比例"))
                        {
                            j++;
                            et.Psbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("上市日期"))
                        {
                            string _temp = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            if (_temp.Trim().Equals("上市日期"))
                            {
                                j++;
                                et.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                _temp = "";
                                continue;
                            }
                        }
                        if (mcTd[j].Value.Contains("中签号公布日"))
                        {
                            j++;
                            et.Gbr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("网上发行中签率"))
                        {
                            j++;
                            et.Zql = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("每中一签资金"))
                        {
                            j++;
                            et.Yqzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("冻结资金"))
                        {
                            j++;
                            et.Djzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("中签号"))
                        {
                            j++;
                            et.Zqh = OperMethod.FormatHtml(mcTd[j].Value);
                            et.Zqh = regex.Replace(et.Zqh, "");
                            continue;
                        }
                        if (mcTd[j].Value.Contains("募集资金用途"))
                        {
                            j++;
                            et.Zjyt = OperMethod.FormatHtml(mcTd[j].Value);
                            et.Zjyt = regex.Replace(et.Zjyt, "");
                            continue;
                        }
                        if (mcTd[j].Value.Contains("担保事项"))
                        {
                            j++;
                            et.Dbsx = OperMethod.FormatHtml(mcTd[j].Value);
                            et.Dbsx = regex.Replace(et.Dbsx, "");
                            continue;
                        }
                        if (mcTd[j].Value.Contains("票面利率"))
                        {
                            j++;
                            et.Pmll = OperMethod.FormatHtml(mcTd[j].Value);
                            et.Pmll = regex.Replace(et.Pmll, "");
                            continue;
                        }
                        if (mcTd[j].Value.Contains("重设条款"))
                        {
                            j++;
                            et.Cstk = OperMethod.FormatHtml(mcTd[j].Value);
                            et.Cstk = regex.Replace(et.Cstk, "");
                            continue;
                        }
                        if (mcTd[j].Value.Contains("回售条款"))
                        {
                            j++;
                            et.Hstk = OperMethod.FormatHtml(mcTd[j].Value);
                            et.Hstk = regex.Replace(et.Hstk, "");
                            continue;
                        }
                        if (mcTd[j].Value.Contains("赎回条款"))
                        {
                            j++;
                            et.Shtk = OperMethod.FormatHtml(mcTd[j].Value);
                            et.Shtk = regex.Replace(et.Shtk, "");
                            continue;
                        }

                        //附属权证资料
                        if (mcTd[j].Value.Contains("权证代码"))
                        {
                            j++;
                            etw.Qzdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("权证名称"))
                        {
                            j++;
                            etw.Qzmc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("权证类型"))
                        {
                            j++;
                            etw.Qzlx = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("权证发行总量"))
                        {
                            j++;
                            etw.Qzfxzl = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("初始行权价格"))
                        {
                            j++;
                            etw.Xqjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                            continue;
                        }
                        if (mcTd[j].Value.Contains("初始行权比例"))
                        {
                            j++;
                            etw.Xqbl = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("权证上市日期"))
                        {
                            j++;
                            etw.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("债券附送权证比例"))
                        {
                            j++;
                            etw.Qzbl = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("权证存续起始日"))
                        {
                            j++;
                            etw.Qsr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("权证存续终止日"))
                        {
                            j++;
                            etw.Zzr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("行权期"))
                        {
                            j++;
                            etw.Xqq = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }
                        if (mcTd[j].Value.Contains("发行人"))
                        {
                            j++;
                            etw.Fxr = OperMethod.StrReplaceHtml(mcTd[j].Value);
                            continue;
                        }

                    }
                    catch (Exception ex)
                    { }
                    #endregion
                }
                #endregion

                //拼Sql
                #region
                sbKzzDetail.Append(" UPDATE [KZZ_Detail]");
                sbKzzDetail.Append(" SET [flag] = 0");
                sbKzzDetail.Append(" ,[zqdm] = '" + et.Zqdm + "'");
                sbKzzDetail.Append(" ,[zqjc] = '" + et.Zqjc + "'");
                sbKzzDetail.Append(" ,[gpdm] = '" + et.Gpdm + "'");
                sbKzzDetail.Append(" ,[gpjc] = '" + et.Gpjc + "'");
                sbKzzDetail.Append(" ,[rgdm] = '" + et.Rgdm + "'");
                sbKzzDetail.Append(" ,[rgjc] = '" + et.Rgjc + "'");
                sbKzzDetail.Append(" ,[sgdm] = '" + et.Sgdm + "'");
                sbKzzDetail.Append(" ,[sgjc] = '" + et.Sgjc + "'");
                sbKzzDetail.Append(" ,[xyjb] = '" + et.Xyjb + "'");
                sbKzzDetail.Append(" ,[pjjg] = '" + et.Pjjg + "'");
                sbKzzDetail.Append(" ,[ztq] = '" + et.Ztq + "'");
                sbKzzDetail.Append(" ,[ztjg] = " + et.Ztjg + "");
                sbKzzDetail.Append(" ,[fxfe] = " + et.Fxfe + "");
                sbKzzDetail.Append(" ,[fxjg] = " + et.Fxjg + "");
                sbKzzDetail.Append(" ,[zqqx] = '" + et.Zqqx + "'");
                sbKzzDetail.Append(" ,[fxbl] = '" + et.Fxbl + "'");
                sbKzzDetail.Append(" ,[sgrq] = '" + et.Sgrq + "'");
                sbKzzDetail.Append(" ,[psbl] = " + et.Psbl + "");
                sbKzzDetail.Append(" ,[ssrq] = '" + et.Ssrq + "'");
                sbKzzDetail.Append(" ,[gbr] = '" + et.Gbr + "'");
                sbKzzDetail.Append(" ,[zql] = " + et.Zql + "");
                sbKzzDetail.Append(" ,[yqzj] = " + et.Yqzj + "");
                sbKzzDetail.Append(" ,[djzj] = " + et.Djzj + "");
                sbKzzDetail.Append(" ,[zqh] = '" + et.Zqh + "'");
                sbKzzDetail.Append(" ,[zjyt] = '" + et.Zjyt + "'");
                sbKzzDetail.Append(" ,[dbsx] = '" + et.Dbsx + "'");
                sbKzzDetail.Append(" ,[pmll] = '" + et.Pmll + "'");
                sbKzzDetail.Append(" ,[cstk] = '" + et.Cstk + "'");
                sbKzzDetail.Append(" ,[hstk] = '" + et.Hstk + "'");
                sbKzzDetail.Append(" ,[shtk] = '" + et.Shtk + "'");
                sbKzzDetail.Append(" ,[createtime] = '" + DateTime.Now + "'");
                sbKzzDetail.Append(" WHERE id=" + _ID);

                //Warrant
                if (et.Zqjc.Contains("转债").Equals(false))
                {
                    sbWarrant.Append("INSERT INTO [KZZ_Warrant] ([id] ,[qzdm] ,[qzmc] ,[qzlx] ,[qzfxzl] ,[xqjg] ,[xqbl] ");
                    sbWarrant.Append(" ,[ssrq] ,[qzbl] ,[qsr] ,[zzr] ,[xqq] ,[fxr]) ");
                    sbWarrant.Append(" VALUES (" + _ID + " ,'" + etw.Qzdm + "' ,'" + etw.Qzmc + "' ,'" + etw.Qzlx + "' ," + etw.Qzfxzl + " ," + etw.Xqjg + " ");
                    sbWarrant.Append(" ,'" + etw.Xqbl + "' ,'" + etw.Ssrq + "' ,'" + etw.Qzbl + "' ,'" + etw.Qsr + "' ,'" + etw.Zzr + "' ,'" + etw.Xqq + "' ,'" + etw.Fxr + "')");
                }
                #endregion
            }

            if (!string.IsNullOrEmpty(_Content))
            {
                using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(sbKzzDetail.ToString()))
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbKzzDetail.ToString(), null);
                            if (!string.IsNullOrEmpty(sbWarrant.ToString()))
                            {
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, "DELETE FROM KZZ_Warrant WHERE ID=" + _ID, null);
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbWarrant.ToString(), null);
                            }
                            trans.Commit();
                            sbKzzDetail = new StringBuilder();
                            sbWarrant = new StringBuilder();
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            Console.WriteLine(ex.Message);
                        }
                        finally
                        {
                            trans.Dispose();
                            conn.Close();
                        }
                    }
                }
                return "信息更新成功!";
            }
            else
                return "链接错误或地址不能访问!";

        }


        /// <summary>
        /// 采集新股上会 http://data.eastmoney.com/xg/gh/default.html UrlList
        /// </summary>
        /// <param name="page">传入采集第几页,page=0采集所有页</param>
        private static void IrtShListUrl(int page)
        {
            StringBuilder sql = new StringBuilder();
            List<ShDetailEntity> ListAll = (List<ShDetailEntity>)NewsList.ShListAll("");
            DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
            string _url = "", _Content = "";
            int _page = 1;
            if (page == 0)
            {
                _url = "http://data.eastmoney.com/xg/gh/default.html";
                _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                Match mc = Regex.Match(_Content, "(?<=<tr class=\"list_pager\">)[\\s\\S]*?(?=</tr>)");
                if (mc.Length > 0)
                {
                    Match mc2 = Regex.Match(mc.Value, "(?<=共)[\\s\\S]*?(?=页)", RegexOptions.IgnoreCase);
                    if (mc2.Length > 0)
                        _page = OperMethod.ToInt(OperMethod.StrReplaceHtml(mc2.Value));
                }
            }

            for (int i = 1; i <= _page; i++)
            {
                try
                {
                    _url = "http://data.eastmoney.com/xg/gh/sbrq/" + i.ToString() + ".html";
                    _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mc = Regex.Match(_Content, "(?<=class=\"rpager\">当前第)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mc.Value))
                    {
                        #region

                        MatchCollection mc2 = Regex.Matches(mc.Value, "<tr[^>][\\S\\s]*?>[\\S\\s]*?</tr>", RegexOptions.IgnoreCase);
                        for (int j = 0; j < mc2.Count; j++)
                        {
                            try
                            {
                                MatchCollection mcTd = Regex.Matches(mc2[j].Value, "<td>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                                if (mcTd.Count == 11 && (mc2[j].Value.Contains("class=\"list_odd\"") || mc2[j].Value.Contains("class=\"list_eve\">")))
                                {
                                    ShDetailEntity et = new ShDetailEntity();
                                    Match mcUrl = Regex.Match(mcTd[9].Value, "(?<=href=\")[\\s\\S]*?(?=\")", RegexOptions.IgnoreCase);
                                    et.Url = "http://data.eastmoney.com" + OperMethod.StrReplaceHtml(mcUrl.Value.Trim());
                                    et.Sbrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[2].Value), _ErrDt);
                                    et.Dqzt = OperMethod.StrReplaceHtml(mcTd[3].Value);
                                    et.Shrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[4].Value), _ErrDt);
                                    et.Sgrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[5].Value), _ErrDt);
                                    et.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[6].Value), _ErrDt);
                                    et.Ssdd = OperMethod.StrReplaceHtml(mcTd[8].Value);

                                    List<ShDetailEntity> MidList = (List<ShDetailEntity>)ListAll.Where(o => o.Url.Equals(et.Url)).ToList();
                                    if (MidList == null || MidList.Count < 1)
                                    {
                                        sql.Append("insert SH_Detail (url,flag,createtime,sbrq,dqzt,Shrq,Sgrq,Ssrq,Ssdd) values ('" + et.Url + "',-1,'" + DateTime.Now + "','" + et.Sbrq + "','" + et.Dqzt + "','" + et.Shrq + "','" + et.Sgrq + "','" + et.Ssrq + "','" + et.Ssdd + "')      ;\n");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("采集新股上会列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                                //LogFile.WriteLog("采集新股上会列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                            }
                        }

                        #endregion
                    }

                    if (!string.IsNullOrEmpty(sql.ToString()))
                    {
                        int n = SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        sql = new StringBuilder();
                        Console.WriteLine("本页page=" + i.ToString() + "采集信息" + n.ToString() + "条");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集新股上会第" + i + "页信息时出错");
                    //LogFile.WriteLog("采集新股上会第" + i + "页信息时出错");
                }
            }
        }


        /// <summary>
        /// 更新新股过会　UrlList　信息
        /// </summary>
        private static void UpShListByUrl()
        {
            List<ShDetailEntity> MidList = (List<ShDetailEntity>)NewsList.ShListAll(" and flag=-1");
            for (int i = 0; i < MidList.Count; i++)
            {
                try
                {
                    Console.WriteLine("采集第i=" + i.ToString() + "条信息");
                    string _url = MidList[i].Url;
                    int _ID = MidList[i].ID;
                    UpShListByUrl(_url, _ID);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集新股上会第i=" + i.ToString() + "条信息异常" + ex.Message);
                    //LogFile.WriteLog("采集新股上会第i=" + i.ToString() + "条信息异常" + ex.Message);
                }
            }
            Console.WriteLine("新股上会信息更新成功");
        }

        private static string UpShListByUrl(string _url, int _ID)
        {
            Regex regex = new Regex("<td[^>][\\S\\s]*?>|</td>|<div[^>][\\S\\s]*?>|</div>");
            //_url = "http://data.eastmoney.com/xg/gh/detail/corp_209.html#list";
            string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
            Match mcSubCon = Regex.Match(_Content, "(?<=id=\"content\"  class=\"mainbox\">)[\\s\\S]*?(?=id=\"footer\">)", RegexOptions.IgnoreCase);
            if (!string.IsNullOrEmpty(mcSubCon.Value))
            {
                //SH_Detail详细资料
                #region
                StringBuilder sbDetail = new StringBuilder();
                Match mcDetail = Regex.Match(mcSubCon.Value, "(?<=——新股上会详细概况)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                if (!string.IsNullOrEmpty(mcDetail.Value))
                {
                    ShDetailEntity et = new ShDetailEntity();
                    MatchCollection mcTd = Regex.Matches(mcDetail.Value, "<td[\\S\\s]*?>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                    DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
                    for (int j = 0; j < mcTd.Count; j++)
                    {
                        #region
                        try
                        {
                            if (mcTd[j].Value.Contains("公司名称"))
                            {
                                j++;
                                et.Gsmc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("发行前总股本"))
                            {
                                j++;
                                et.Fxqzgb = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("拟发行后总股本"))
                            {
                                j++;
                                et.Fxhzgb = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("拟发行数量"))
                            {
                                j++;
                                et.Fxsl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("占发行后总股本"))
                            {
                                j++;
                                et.Zbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value.Replace("%", "")));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("重要财务指标"))
                            {
                                j++;
                                et.Cwjb = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("每股收益"))
                            {
                                j++;
                                et.Mgsy = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("发行前每股净资产"))
                            {
                                j++;
                                et.Jzc = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("每股现金流量"))
                            {
                                j++;
                                et.Xjll = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("净资产收益率"))
                            {
                                j++;
                                et.Syl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                continue;
                            }
                            if (mcTd[j].Value.Contains("主营业务"))
                            {
                                j++;
                                et.Zyyw = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("利润分配"))
                            {
                                j++;
                                et.Lrfp = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("主承销商"))
                            {
                                j++;
                                et.Zcxs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                            if (mcTd[j].Value.Contains("承销方式"))
                            {
                                j++;
                                et.Cxfs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Detail取字段" + mcTd[j].Value + "附近异常:" + ex.Message);
                            //LogFile.WriteLog("Detail取字段" + mcTd[j].Value + "附近异常:" + ex.Message);
                        }
                        #endregion
                    }

                    //拼sbDetail Sql
                    #region
                    sbDetail.Append("UPDATE [SH_Detail]");
                    sbDetail.Append(" SET [flag] = 0");
                    sbDetail.Append(" ,[gsmc] = '" + et.Gsmc + "'");
                    sbDetail.Append(" ,[fxqzgb] = " + et.Fxqzgb + "");
                    sbDetail.Append(" ,[fxhzgb] = " + et.Fxhzgb + "");
                    sbDetail.Append(" ,[fxsl] = " + et.Fxsl + "");
                    sbDetail.Append(" ,[zbl] = " + et.Zbl + "");
                    sbDetail.Append(" ,[cwjb] = '" + et.Cwjb + "'");
                    sbDetail.Append(" ,[mgsy] = " + et.Mgsy + "");
                    sbDetail.Append(" ,[jzc] = " + et.Jzc + "");
                    sbDetail.Append(" ,[xjll] = " + et.Xjll + "");
                    sbDetail.Append(" ,[syl] = " + et.Syl + "");
                    sbDetail.Append(" ,[zyyw] = '" + et.Zyyw + "'");
                    sbDetail.Append(" ,[lrfp] = '" + et.Lrfp + "'");
                    sbDetail.Append(" ,[zcxs] = '" + et.Zcxs + "'");
                    sbDetail.Append(" ,[cxfs] = '" + et.Cxfs + "'");
                    sbDetail.Append(" ,[createtime] = '" + DateTime.Now + "'");
                    sbDetail.Append(" WHERE ID=" + _ID);
                    Console.WriteLine("Detail拼Sql完成");
                    #endregion
                }
                #endregion

                //Sh_Invset投资项目
                #region
                StringBuilder sbInvset = new StringBuilder();
                Match mcInvset = Regex.Match(mcSubCon.Value, "(?<=募集资金用途将用于的项目</div>)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                if (!string.IsNullOrEmpty(mcInvset.Value))
                {
                    MatchCollection mcTr = Regex.Matches(mcInvset.Value, "(?<=<tr)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                    for (int k = 0; k < mcTr.Count; k++)
                    {
                        try
                        {
                            if (mcTr[k].Value.Contains("class=\"list_eve\">") || mcTr[k].Value.Contains("class=\"list_odd\">"))
                            {
                                MatchCollection mcTd = Regex.Matches(mcTr[k].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                                if (mcTd.Count == 3)
                                {
                                    ShInvsetEntity et = new ShInvsetEntity();
                                    et.Xmmc = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                    et.tzje = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[2].Value));
                                    sbInvset.Append("Insert into SH_Invset (id,xmmc,tzje) values (" + _ID + ",'" + et.Xmmc + "'," + et.tzje + ")    ;\n");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("新股过会募集资金用途将用于的项目异常:" + ex.Message);
                            //LogFile.WriteLog("新股过会募集资金用途将用于的项目异常:" + ex.Message);
                        }
                    }
                }
                Console.WriteLine("取Sh_Invset投资项目信息完成");
                #endregion

                //XG_Indicators财务指标
                #region
                StringBuilder sbIndicator = new StringBuilder();
                Match mcIndicator = Regex.Match(mcSubCon.Value, "(?<=最近三年财务指标</div>)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                if (!string.IsNullOrEmpty(mcIndicator.Value))
                {
                    List<EntityIndicatorCol> CList = new List<EntityIndicatorCol>();
                    MatchCollection mcTr = Regex.Matches(mcIndicator.Value, "(?<=<tr)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                    for (int m = 0; m < mcTr.Count; m++)
                    {
                        try
                        {
                            EntityIndicatorCol cet = new EntityIndicatorCol();

                            if (mcTr[m].Value.Contains("class=\"subhead\">"))
                            {
                                MatchCollection mcTd = Regex.Matches(mcTr[m].Value, "<th[\\S\\s]*?>[\\S\\s]*?</th>", RegexOptions.IgnoreCase);
                                if (mcTd.Count > 0)
                                {
                                    cet.zd = OperMethod.StrReplaceHtml(mcTd[0].Value);
                                    cet.c1 = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                    cet.c2 = OperMethod.StrReplaceHtml(mcTd[2].Value);
                                    cet.c3 = OperMethod.StrReplaceHtml(mcTd[3].Value);
                                    CList.Add(cet);
                                }
                                continue;
                            }

                            if (mcTr[m].Value.Contains("class=\"list_eve\">") || mcTr[m].Value.Contains("class=\"list_odd\">"))
                            {
                                MatchCollection mcTd = Regex.Matches(mcTr[m].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                                if (mcTd.Count > 0)
                                {
                                    cet.zd = OperMethod.StrReplaceHtml(mcTd[0].Value);
                                    cet.c1 = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                    cet.c2 = OperMethod.StrReplaceHtml(mcTd[2].Value);
                                    cet.c3 = OperMethod.StrReplaceHtml(mcTd[3].Value);
                                    CList.Add(cet);
                                }
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("解析装载到List出错:" + ex.Message);
                            //LogFile.WriteLog("解析装载到List出错:" + ex.Message);
                        }
                    }

                    if (CList.Count == 11)
                    {
                        sbIndicator.Append(" INSERT INTO [SH_Indicators] ");
                        sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                        sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c1 + "'," + OperMethod.ToDeceimal(CList[1].c1) + "," + OperMethod.ToDeceimal(CList[2].c1) + "," + OperMethod.ToDeceimal(CList[3].c1) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c1) + "," + OperMethod.ToDeceimal(CList[5].c1) + "," + OperMethod.ToDeceimal(CList[6].c1) + "," + OperMethod.ToDeceimal(CList[7].c1) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c1) + "," + OperMethod.ToDeceimal(CList[9].c1) + "," + OperMethod.ToDeceimal(CList[10].c1) + ")    ;\n");

                        sbIndicator.Append(" INSERT INTO [SH_Indicators] ");
                        sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                        sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c2 + "'," + OperMethod.ToDeceimal(CList[1].c2) + "," + OperMethod.ToDeceimal(CList[2].c2) + "," + OperMethod.ToDeceimal(CList[3].c2) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c2) + "," + OperMethod.ToDeceimal(CList[5].c2) + "," + OperMethod.ToDeceimal(CList[6].c2) + "," + OperMethod.ToDeceimal(CList[7].c2) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c2) + "," + OperMethod.ToDeceimal(CList[9].c2) + "," + OperMethod.ToDeceimal(CList[10].c2) + ")    ;\n");

                        sbIndicator.Append(" INSERT INTO [SH_Indicators] ");
                        sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                        sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c3 + "'," + OperMethod.ToDeceimal(CList[1].c3) + "," + OperMethod.ToDeceimal(CList[2].c3) + "," + OperMethod.ToDeceimal(CList[3].c3) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c3) + "," + OperMethod.ToDeceimal(CList[5].c3) + "," + OperMethod.ToDeceimal(CList[6].c3) + "," + OperMethod.ToDeceimal(CList[7].c3) + " ");
                        sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c3) + "," + OperMethod.ToDeceimal(CList[9].c3) + "," + OperMethod.ToDeceimal(CList[10].c3) + ")    ;\n");
                    }
                }
                Console.WriteLine("取Sh_Indicators最近三年财务指标完成");
                #endregion

                //XG_Partner主要股东
                #region
                StringBuilder sbPartner = new StringBuilder();
                Match mcPartner = Regex.Match(mcSubCon.Value, "(?<=主要股东</div>)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                if (!string.IsNullOrEmpty(mcPartner.Value))
                {
                    MatchCollection mcTr = Regex.Matches(mcPartner.Value, "(?<=class=\"list_eve\">)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                    for (int x = 0; x < mcTr.Count; x++)
                    {
                        try
                        {
                            MatchCollection mcTd = Regex.Matches(mcTr[x].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                            if (mcTd.Count == 4)
                            {
                                ShPartnerEntity et = new ShPartnerEntity();
                                et.Gdmc = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                et.Cgsl = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[2].Value));
                                et.Gbbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[3].Value));
                                sbPartner.Append("INSERT INTO [SH_Partner] ([id],[gdmc],[cgsl],[gbbl]) VALUES (" + _ID + ",'" + et.Gdmc + "'," + et.Cgsl + "," + et.Gbbl + ")    ;\n");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("新股上会主要股东异常:" + ex.Message);
                            //LogFile.WriteLog("新股上会主要股东异常:" + ex.Message);
                        }
                    }
                }
                Console.WriteLine("采集更新新股上会XG_Partner主要股东完成");
                #endregion

                //执行Sql
                #region
                using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(sbDetail.ToString()))
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbDetail.ToString(), null);
                            if (!string.IsNullOrEmpty(sbInvset.ToString()))
                            {
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, "DELETE FROM SH_Invset WHERE ID=" + _ID, null);
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbInvset.ToString(), null);
                            }
                            int n = 0;
                            if (!string.IsNullOrEmpty(sbIndicator.ToString()))
                            {
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, "DELETE FROM SH_Indicators WHERE ID=" + _ID, null);
                                n = SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbIndicator.ToString(), null);
                            }
                            if (!string.IsNullOrEmpty(sbPartner.ToString()))
                            {
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, "DELETE FROM SH_Partner WHERE ID=" + _ID, null);
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbPartner.ToString(), null);
                            }
                            trans.Commit();
                            Console.WriteLine("ID=" + _ID + ",Url=" + _url + "新股上会信息更新成功!");
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            Console.WriteLine("执行新股上会Sql异常,ID:" + _ID + ":" + ex.Message);
                            //LogFile.WriteLog("执行新股上会Sql异常,ID:" + _ID + ":" + ex.Message);
                        }
                        finally
                        {
                            sbDetail = new StringBuilder();
                            sbInvset = new StringBuilder();
                            sbIndicator = new StringBuilder();
                            sbPartner = new StringBuilder();
                        }
                    }
                }
                #endregion
                return "信息更新成功!";
            }
            else
                return "链接错误或地址不能访问!";
        }

    }

    public class EntityIndicatorCol
    {
        public string zd { get; set; }
        public string c1 { get; set; }
        public string c2 { get; set; }
        public string c3 { get; set; }
    }
}
